<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | 王勇程 <laughskydragon@qq.com>                         |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\validate;

/**
 * 积分验证器
 */
class Points extends ValidateBase
{
    
    // 验证规则
    protected $rule = [
        'id'            => 'require|integer|gt:0',
        'user_id'       => 'require|integer|gt:0',
        'points'        => 'require|integer',
        'type'          => 'require|in:1,2',
        'source'        => 'require|in:1,2,3,4,5,6,7,8,9,10',
        'remark'        => 'length:0,255',
        'order_id'      => 'integer|gt:0',
        'expire_time'   => 'date',
        'status'        => 'in:0,1',
    ];

    // 验证提示
    protected $message = [
        'id.require'        => '积分记录ID不能为空',
        'id.integer'        => '积分记录ID必须为整数',
        'id.gt'             => '积分记录ID必须大于0',
        'user_id.require'   => '用户ID不能为空',
        'user_id.integer'   => '用户ID必须为整数',
        'user_id.gt'        => '用户ID必须大于0',
        'points.require'    => '积分数量不能为空',
        'points.integer'    => '积分数量必须为整数',
        'type.require'      => '积分类型不能为空',
        'type.in'           => '积分类型值不正确',
        'source.require'    => '积分来源不能为空',
        'source.in'         => '积分来源值不正确',
        'remark.length'     => '备注长度不能超过255个字符',
        'order_id.integer'  => '订单ID必须为整数',
        'order_id.gt'       => '订单ID必须大于0',
        'expire_time.date'  => '过期时间格式不正确',
        'status.in'         => '状态值不正确',
    ];

    // 应用场景
    protected $scene = [
        'add'       => ['user_id', 'points', 'type', 'source'],
        'edit'      => ['id', 'points', 'type', 'source'],
        'query'     => ['user_id'],
        'exchange'  => ['user_id', 'points'],
        'expire'    => ['expire_time'],
    ];
}